package org.edu.controller;

import javax.annotation.Resource;

import org.apache.struts2.ServletActionContext;
import org.edu.bean.TmPersoninfo;
import org.edu.common.PageView;
import org.edu.common.QueryResult;
import org.edu.service.TmPersoninfoService;

import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class TmPersonInfoController extends ActionSupport{
	@Resource
	private TmPersoninfoService tmPersoninfoService; 
	
	private TmPersoninfo entity;
	private String cardno;
	private String message;
	
	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String getCardno() {
		return cardno;
	}

	public void setCardno(String cardno) {
		this.cardno = cardno;
	}
	private int page = 1;
	
	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public TmPersoninfo getEntity() {
		return entity;
	}

	public void setEntity(TmPersoninfo entity) {
		this.entity = entity;
	}

	@Override
	public String execute() throws Exception {
		try {
			tmPersoninfoService.save(entity);
			addActionMessage("基本信息登记成功【"+entity.getCardno()+"】");
		} catch (Exception e) {
			addActionMessage("基本信息登记失败【"+entity.getCardno()+"】");
			e.printStackTrace();
		}
		return "message";
	}
	public String check() throws Exception {
		TmPersoninfo personinfo = tmPersoninfoService.findByCardNo(cardno);
		if(personinfo != null){
			this.message = "该纳税人基本信息已经存在，无法继续登记";
		}else{
			this.message = "该纳税人可以进行登记";
		}
		return "check";
	}
	public String list() throws Exception {
		PageView<TmPersoninfo> pageView = new PageView<TmPersoninfo>(20,this.page);
		QueryResult<TmPersoninfo> qr = tmPersoninfoService.getQueryResult(pageView.getFirstResult()
				,pageView.getMaxresult());
		pageView.setQueryResult(qr);
		ServletActionContext.getRequest().setAttribute("pageView", pageView);
		return SUCCESS;
	}
	
}
